package cn.fzm.controller;

import cn.fzm.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Dremeue
 * @create 2019-09-29 23:39
 **/
@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/testReturnString")
    public String testReturnString(Model model) {
        System.out.println("testReturnString 执行了...");

        // 模拟从数据库中查数据
        User user = new User();
        user.setUsername("要赢");
        user.setAge(20);

        model.addAttribute("user", user);

        return "success";
    }

    @RequestMapping("/testAjax")
    public @ResponseBody User testAjax(@RequestBody User user) {
        System.out.println("testReturnString 执行了...");

        System.out.println(user);

        // 模拟从数据库中查数据
        user.setUsername("要赢");
        user.setAge(20);

        return user;
    }
}
